/*
 * ParameterDescription.java
 * 
 * last update: 16.01.2010 by Stefan Saru
 * 
 * author:	Alec(panovici@elcom.pub.ro)
 * 
 * Obs:
 */
package engine;


import java.util.*;
import middle.*;

class ParameterDescription extends Symbol{

	ExpressionDescription ex;
	Result r;

	ParameterDescription(String name, int lineNo){
		super(name, lineNo);
		xConsole.debug("new parameter " + name);
	}

	void assign(ExpressionDescription ex){
		this.ex = ex;
	}

	void define(Result r){
		xConsole.debug("defin param " + name + " to " + r);
		this.r = r;
	}

	public Object instantiate(NameSpace ns, ScopeNode thisScope)throws ParseException{
		try{
			if(r ==null){
				if(ex == null)
					throw new ParseException("undefined parameter");
				r = ex.instantiate(ns).evaluate();
			}
			return new Parameter(ns, this, r);
		}catch(Exception e){
			throw new ParseException(ns.desc.toString(lineNo) +
					" error:exception while evaluating parameter \"" +
					name + "\": " + e);
		}
	}

	public String toString(){
		return name;
	}

	public int getType(){
		return paramType;
	}
}

